package de.fhhannover.inform.hnefatafl.gui;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;


public class OptionPanel extends JPanel implements ChangeListener{
	
	private static final long serialVersionUID = 1L;
	
	public JSlider        slider;
	public AttackerOption attackerOption;
	public DefenderOption defenderOption;
	public JButton		  gameStarter;
	
	
	public OptionPanel(){
		this.setLayout(new GridBagLayout());
        this.setBorder(new TitledBorder(new EtchedBorder(), "Optionen"));
        this.setPreferredSize(new java.awt.Dimension(188, 306));
               
       	slider = new JSlider(JSlider.HORIZONTAL, 1, 5, 3);
       	slider.setPaintTicks(true);
       	slider.setMajorTickSpacing(1);
       	this.add(slider, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
       	slider.addChangeListener(this);
       	
       	
       	TitledBorder tb = new TitledBorder(new EtchedBorder());
       	slider.setBorder(tb);  
        tb.setTitle("KI-Denkzeit = 3 sek.");

        attackerOption = new AttackerOption();
        this.add(attackerOption, new GridBagConstraints(1, 1, 1, 1, 1.0, 1.0, GridBagConstraints.NORTH, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
		
		defenderOption = new DefenderOption();
		this.add(defenderOption, new GridBagConstraints(1, 2, 1, 1, 1.0, 1.0, GridBagConstraints.NORTH, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
		
		gameStarter = new JButton("Spiel starten!");
		this.add(gameStarter, new GridBagConstraints(1, 3, 2, 2, 2.0, 2.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
	}


	@Override
	public void stateChanged(ChangeEvent arg0) {
        int value = slider.getValue();
        TitledBorder tb = (TitledBorder) slider.getBorder();
        tb.setTitle("KI-Denkzeit = " + String.valueOf(value) + " sek.");
        } 


}
